package com.car.util;
/**
 * 生成String类型的SUK编码
 * @author Administrator
 *
 */

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class SUKUtil {

	private final Logger logger = LoggerFactory.getLogger(getClass());
	/**
	 * 1.提供对外调用的方法 2.返回当前日期yyyyMMdd 3.生成随机数3位 4.ZD20180803001
	 */
	static SimpleDateFormat sd = new SimpleDateFormat("HmSSS");

	/**
	 * 初始化日期格式
	 * 
	 * @return
	 */
	public static String dateFormat() {
		return sd.format(new Date());
	}

	/**
	 * 生成随机数
	 * 
	 * @return
	 */
	private static String random() {
		int number = (int) (Math.random() * 999) + 1;
		return number < 10 ? "" + number : number < 100 ? "" + number : "" + number;
	}

	/**
	 * 生成数字码
	 */

	private static String randomUtil() {
		Random r = new Random();
		String code = "";
		for (int i = 0; i < 4; ++i) {
			int temp = r.nextInt(52);
			char x = (char) (temp < 26 ? temp + 97 : (temp % 26) + 65);
			code += x;
		}
		return code;
	}

	/**
	 * 获取SKU编码
	 * 
	 * @return
	 */
	public static String getRandom() {
		return randomUtil() + dateFormat();
	}

	/**
	 * 密码加密
	 * 
	 * @param password
	 * @return
	 */
	public static String cryptedPwd(String password) {
		return new Md5Hash(password).toString();
	}
}
